"use strict";

/**
 * product controller
 */

const { createCoreController } = require("@strapi/strapi").factories;

module.exports = createCoreController('api::product.product', ({ strapi }) => ({

    async findBySn(ctx) {
        try {
            const { sn } = ctx.query
            const entry = await strapi.db.query('api::product.product').findOne({
                where: { sn },
                populate: true,
            });
            ctx.body = { data: entry }
        } catch (err) {
            ctx.body = { data: null, message: err }
        }
    },
}));

